SIMPLE DIGITAL FILTER DESIGN
INTRO
A simple digital lowpass filter can be created with an element of one sample time delay. Since the circuit contains a feedback loop it has an infinite impulse response (IIR-filter).
convert_model(file2sim); % create HTML-version of simulinkfile
disp(get_link('-> create IIR-Filter in Simulink',file2sim));
[sweep,sweep_LPF,~,~,t]=sim_model(file2sim);
titles={'log-sweep';'filtered log-sweep'};
ylabels={'Amplitude';'Amplitude'};
plot_MOD(t,sweep,sweep_LPF,'titles',titles,'ylabels',ylabels)
The difference equation of this filter is 
The filter coefficients should be calculated that we obtain a critical damped filter of a first order comparable to an analog RC-lowpass. Therfore the charging and discharging curves are viewed and virtually digitized.
FILTER COEFFICIENTS
The exponential shape of the discharge curve of an RC-lowpass can be described by the formula 
Where
. A digital system has only discrete sample times, so the analog time is replaced by
. Let the maximum values of the in- and outputs be one, then we have
and
. According to the difference equation we get the output values with increasing time:
The digitized output of the anaolg formula is 
. If we define a normalized cutoff frequency
the output can be written as 
Since the difference equation and the digitezed output should be identical it must be true that 
. Therefore the first coefficient 
.
The charging curve of an RC-lowpass has an exponential shape and the output approaches the input level with increasing time.
Assumed that the elapsed time is long enough, it can be said, that the outputs have reached the input level. For a digital system with an input
, the difference equation is
.
FILTER CASCADING
The designed filter is of first order. If n independent and identical filters are cascaded, then the individual cutoff frequency fci of one filter has to be higher than the cutoff frequency of the overall system. The correction value can be obtained by the equation 
. The more filters are cascaded, the higher the cutoff frequency of one individual filter gets. Anyway, the Nyquist theorem must not be violated.
%% lowpass filters of higher orders
corr=(2^(1/k)-1)^(1/2); % fgn of individual filter has to be higher than fg
error('increase samplerate or reduce filter-order!')
LPF=tf(a,[1 -b],1/fs,'variable','z^-1');
h1=bodeplot(LPF); % normalized frequency response
setoptions(h1,'FreqUnits','Hz');